﻿<div class="layui-form toolbar " id = "audit-operate-search-div" lay-filter="audit-operate-search-div">
    <div class="layui-form-item layui-form-pane">
        <div class="layui-inline">
            <label class="layui-form-label">帐号</label>
            <div class="layui-input-inline">
                <input type="text" name="account" placeholder="请输入帐号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="usernameLike" placeholder="请输入用户名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">操作时间</label>
            <!--<div class="layui-input-inline">-->
            <!--<input type="text" class="createTime" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" lay-key="1">-->
            <!--</div>-->
            <div class="layui-input-inline" >
                <input type="text"  name="createTimeGt" autocomplete="off" placeholder="请输入开始时间" class="layui-input createTime">
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline" >
                <input type="text" name="createTimeLt"  autocomplete="off" placeholder="请输入结束时间" class="layui-input createTime">
            </div>
        </div>
        <div class="layui-inline ">
            <button id="audit-operate-search-btn" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>
    </div>
</div>
<table class="layui-table layui-form" id="audit-operate-table" lay-filter="audit-operate-table"></table>
<!-- 表格toobar -->
<div class="layui-table-tool" style="display: none" id="audit-operate-toolbar">
    <div class="layui-table-tool-temp">
        <button id="audit-operate-export-btn" class="layui-btn icon-btn layui-btn-primary layui-btn-sm"><i class="layui-icon">&#xe67d;</i>导出
        </button>
    </div>
</div>
<!-- 表格操作列 -->
<div type="text/html" style="display: none" id="audit-operate-operate">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-perm = 'audit-operate-del' lay-event="del">删除</a>
</div>

<script>

    layui.use(['layer', 'form', 'table', 'util', 'admin','laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var laydate = layui.laydate;
        // form.render("select","audit-operate-search-div")
        form.render("","audit-operate-search-div")
        laydate.render({
            elem: '#audit-operate-search-div [name="createTimeGt"]', //指定元素
            type:"datetime",
        });
        laydate.render({
            elem: '#audit-operate-search-div [name="createTimeLt"]', //指定元素
            type:"datetime",
        });
        admin.renderTable({
            id:"audit-operate-table",
            search:"audit-operate-search",
            toolbar: '#audit-operate-toolbar',
            defaultToolbar:['filter'],
            url:"audit/operate/list",
            cols:[[
                {type: 'checkbox'},
                {field: 'username', title: '用户名'},
                {   field:"createTime",sort:true,
                    templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '操作时间'
                },
                {field: 'ip', title: 'IP'},
                {field: 'operate', title: '操作内容'},
                {field: 'type', title: '操作类型',templet:function(d){
                    switch (d.type) {
                        case "add":return "新增";
                        case "update":return "修改";
                        case "del":return "删除";
                        case "query":return "查询";
                    }return "其它";
                    }},
                {field: 'uri', title: '路径'},
                {field: 'params', title: '参数'},
                {align: 'center',toolbar: '#audit-operate-operate',width:"10%", title: '操作'}
            ]],
            initSort:{field:"createTime",type:"desc"}
        })

        // 工具条点击事件
        table.on('tool(audit-operate-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent ==="del"){
                del(obj.data.id);
            }
        });

        function del(userId){
            admin.delete("audit/operate/delete/"+userId,{},function(){
                layer.msg("删除成功", {icon: 1});
                table.reload('audit-operate-table')
            })
        }

    });
</script>

</body>
</html>